package com.hq.fxh.imageLoader;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.hq.fxh.No0_ChengQu.Activity.BaseActivity;
import com.hq.fxh.R;
import com.hq.fxh.imageLoader.bean.ImageFolder;
import com.hq.fxh.imageLoader.video.VideoFolder;

import java.util.List;

import cn.jiguang.analytics.android.api.JAnalyticsInterface;


public class FolderPictureActivity extends BaseActivity {

    private RecyclerView recyclerView;
    private List<ImageFolder> mImageFolders;
    private ImageFolderAdapter picAdapter;
    private ImageView back;
    private List<VideoFolder> mVideoFolders;
    private VideoFolderAdapter vidAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_folder_picture;
    }



    @Override
    protected void initView() {
        recyclerView = (RecyclerView)findViewById(R.id.recyclerView);
        back = (ImageView) findViewById(R.id.back);
    }

    @Override
    protected void initData() {
        LinearLayoutManager layoutManager = new LinearLayoutManager(FolderPictureActivity.this);
        recyclerView.setLayoutManager(layoutManager);
        layoutManager.setOrientation(OrientationHelper. VERTICAL);
//如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        recyclerView.setHasFixedSize(true);

        Intent intent = this.getIntent();
        mImageFolders = (List<ImageFolder>) intent.getSerializableExtra("ImageFolders");
        mVideoFolders = (List<VideoFolder>) intent.getSerializableExtra("VideoFolders");
        if (mImageFolders != null) {
            if (picAdapter == null) {
                picAdapter = new ImageFolderAdapter(FolderPictureActivity.this, mImageFolders);
            } else {
                picAdapter.notifyDataSetChanged();
            }
            recyclerView.setAdapter(picAdapter);
        } else if (mVideoFolders!=null){

            if (vidAdapter == null) {
                vidAdapter = new VideoFolderAdapter(FolderPictureActivity.this, mVideoFolders);
            } else {
                vidAdapter.notifyDataSetChanged();
            }
            recyclerView.setAdapter(vidAdapter);
        }


        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        JAnalyticsInterface.onPageStart(this,"本地相册");
    }

    @Override
    protected void onPause() {
        super.onPause();
        JAnalyticsInterface.onPageEnd(this,"本地相册");
    }

}
